package ms.jacrim.framework;

import java.util.ArrayList;
import java.util.List;

import ms.jacrim.pddl.PddlSolution;
import ms.spm.IAppContext;

public class SolutionManager {
	
	public enum ActionStatus {
		PENDING, EXECUTING, ACCOMPLISHED, FAIL
	}
	
	public final IAppContext Context;
	public final ActiveSolution ActiveSolution;
	public final Model Model;
	
	private List<PddlSolution> solutions;

	public SolutionManager(IAppContext context, Model model) {
		Model = model;
		Context = context;
		solutions = new ArrayList<PddlSolution>();
		ActiveSolution = new ActiveSolution();
	}
	
	public List<PddlSolution> collectSolutions(boolean startPlanner) throws Exception {
		solutions.clear();
		
		if (startPlanner)
			Model.Generator.startPlanner();
		// wait until planner terminated
		while (Model.Generator.Status() != SolutionGenerator.Status.READY)
			;
		for (int i = 1, cnt = Model.Generator.AvailableSolution(); i <= cnt; i++) {
			PddlSolution sol = Model.Generator.getSolution(i);
			if (sol != null)
				solutions.add(sol);
		}
		return solutions;
	}
	
	public List<PddlSolution> Solutions() {
		return solutions;
	}

	public void setActiveSolution(PddlSolution pddlSolution) {
		ActiveSolution.setSolution(pddlSolution);
	}
	

}
